#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<string.h>
int main(void)
{
	int fds[2]={0};
	if(-1==pipe(fds)){
		perror("pipe error");
		exit(0);
	}
	switch(fork()){
		case -1:
			perror("fork error");
			exit(0);
		case 0:{
				char rdbuf[64]={0};
				printf("i am child,pid:%d,ppid:%d",getpid(),getppid());
				close(fds[1]);
				while(1){
					read(fds[0],rdbuf,sizeof(rdbuf));
					puts(rdbuf);
					memset(rdbuf,0x0,sizeof(rdbuf));
					sleep(1);
				}
				_exit(0);
			   }
		default:
			   close(fds[0]);
				printf("i am parent,pid:%d,ppid:%d",getpid(),getppid());
				while(1){
					write(fds[1],"hello world",11);
					sleep(1);
				}
				break;

	}
}
